﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Xml.Serialization;

namespace CrazyWorship1
{

    public class Rectangle : INotifyPropertyChanged,IXmlSerializable
    {
        public Rectangle(int left, int top, int width, int height)
        {
            _left = left;
            _top = top;
            _height = height;
            _width = width;
        }
        public Rectangle()
        {
        }
        int _left, _top, _height, _width;
        public int Height
        {
            get
            {
                return _height;
            }
            set
            {
                _height = value;
                NotifyPropertyChanged("Height");
            }
        }
        public int Width
        {
            get
            {
                return _width;
            }
            set
            {
                _width = value;
                NotifyPropertyChanged("Width");
            }
        }
        public int Top
        {
            get
            {
                return _top;
            }
            set
            {
                _top = value;
                NotifyPropertyChanged("Top");
            }
        }
        public int Left
        {
            get
            {
                return _left;
            }
            set
            {
                _left = value;
                NotifyPropertyChanged("Left");
            }
        }
        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(string property)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }


        #endregion

        #region IXmlSerializable Members

        public System.Xml.Schema.XmlSchema GetSchema()
        {
            throw new NotImplementedException();
        }

        public void ReadXml(System.Xml.XmlReader reader)
        {
            reader.ReadStartElement("Bounds");
            this._top = int.Parse(reader.ReadElementContentAsString("top", ""));
            this._height = int.Parse(reader.ReadElementContentAsString("height", ""));
            this._left = int.Parse(reader.ReadElementContentAsString("left", ""));
            this._width = int.Parse(reader.ReadElementContentAsString("width", ""));
            reader.ReadEndElement();
        }

        public void WriteXml(System.Xml.XmlWriter writer)
        {
            writer.WriteStartElement("Bounds");
            writer.WriteElementString("top", _top.ToString());
            writer.WriteElementString("height", _height.ToString());
            writer.WriteElementString("left", _left.ToString());
            writer.WriteElementString("width", _width.ToString());
            writer.WriteEndElement();
        }

        #endregion
    }
}
